package com.jlnx.controller.chain;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlnx.controller.bank.ShowSupplyChainController;
import com.jlnx.dao.ChainEnterpriseDaoImpl;
import com.jlnx.dao.CoreEnterpriseDaoImpl;
import com.jlnx.dao.EnterpriseDaoImpl;
import com.jlnx.dao.FinanceReqDaoImpl;
import com.jlnx.dao.SupplyChainDaoImpl;
import com.jlnx.pojo.ChainEnterprise;
import com.jlnx.pojo.CoreEnterprise;
import com.jlnx.pojo.Enterprise;
import com.jlnx.pojo.FinanceReq;

/*
 * 获取链条企业的所有信息
 */
@WebServlet("/getChainEntMessageController")
public class getChainEntMessageController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获取请求信息
		response.setContentType("application/json;charset=UTF-8;text/html");
		//设置请求编码模式
    	request.setCharacterEncoding("utf-8");
    	
		 ChainEnterpriseDaoImpl dao = new ChainEnterpriseDaoImpl();
		 SupplyChainDaoImpl supplydao = new SupplyChainDaoImpl();
		
				
		 //获取session对象
		 HttpSession hs=request.getSession();
		 //获取登录账号
		 String entNo = ((Enterprise)hs.getAttribute("enterprise")).getEntNo();
		 System.out.println("获取：" + entNo + "信息");
		 
		 //查询是否在白名单中（查询供应链中是否有）
		 System.out.println("白名单" + supplydao.selectSupplyChainListByEntNo(entNo).size());
		 if(supplydao.selectSupplyChainListByEntNo(entNo).size() == 0) {
			 request.setAttribute("isExist", false);
			 request.setAttribute("msg", "企业不在白名单中，无法进行准入申请!");
		 }else {
			 request.setAttribute("isExist", true);
		 }
		 ChainEnterprise chainEnterprise = dao.selectByEntNo(entNo);
		 System.out.println(chainEnterprise.toString());
		 request.setAttribute("chainEntList", chainEnterprise);
		 request.getRequestDispatcher("/main/inEnterpriseReq.jsp").forward(request, response);
				
	}

}
